package com.spa.interfaces.admin;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import com.spa.application.dto.login.LoginDTO;
import com.spa.application.query.admin.AdminLoginQuery;
import com.spa.application.service.common.LoginApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.infrastructure.enums.dict.base.LoginWayEnum;
import com.spa.interfaces.BaseController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("admin")
public class AdminLoginController extends BaseController {

    @Resource
    private LoginApplicationService loginService;

    @PostMapping("/login")
    @SaIgnore
    public ResponseMessage<LoginDTO> shopLogin(@RequestBody AdminLoginQuery query) {
        return responseHelper.success(loginService.adminLogin(query,LoginWayEnum.PASSWORD));
    }

    @PostMapping("/outLogin")
    public ResponseMessage outLogin() {
        StpUtil.logout();
        return responseHelper.success();
    }

}
